<template>
  <div>
    <!-- <FormPanel ref="formPanel" :list="formList" :formType="type" @formChange="formChangeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <FormPanel ref="formPanel1" :list="formList1" :formType="type" @formChange="formChangeHandle1" :isSubmitBtn="false" :collapse="false" labelWidth="110" /> -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <FilterTable
      ref="table"
      height="auto"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    />
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <multiuse-button type="primary" :disabled="!isCan" :click="cancelHidden">取消隐藏</multiuse-button>
      <el-button @click="closeDrawer">关 闭</el-button>
    </div>
  </div>
</template>
<script>
import moment from 'moment';
import { dictionary } from '@/utils/dictMixin';
import { getUser } from '@/assets/js/auth';
import { getRecipient, getInvoiceList, registration, allRegistration, cancelHidden, getInvocieListHidden } from '@/api/omFinance/InvoiceMailManage/InvoiceMailRegist';

export default {
  name: 'SonModel',
  mixins: [dictionary],

  props: ['type', 'rowData'],
  data() {
    this.BaseTable = null;
    this.saveData = null;
    this.saveData1 = null;

    return {
      topFilterList: this.createdSearchFrom(),
      columns: this.createdTable(),
      fetchApi: getInvocieListHidden,
      fetchParams: {
        dealerCode: this.rowData.dealerCode || '',
        powerType: this.rowData.powerType || '',
        buzinessType: this.rowData.buzinessType || ''
      },
      recipientId: '',
      sendId: '',
      ids: [],
      isCan: false,
      showHidden: false
    };
  },
  created() {
    this.getRecipient();
  },
  methods: {
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    async getRecipient() {
      const res = await getRecipient({
        dealerCode: this.rowData.dealerCode || '',
        powerType: this.rowData.powerType || '',
        buzinessType: this.rowData.buzinessType || ''
      });
      if (res.resultCode == 200) {
        let recipientDTO = res.data.recipientDTO;
        let sendDTO = res.data.sendDTO;
        this.recipientId = recipientDTO.id;
        this.sendId = sendDTO.id;
        // this.formList.map(x => {
        //   if (x.fieldName == 'dealerCode') {
        //     x.initialValue = this.rowData.dealerCode;
        //   } else if (x.fieldName == 'dealerName') {
        //     x.initialValue = this.rowData.dealerName;
        //   } else if (x.fieldName == 'djr' || x.fieldName == 'djrq') {
        //   } else {
        //     x.initialValue = sendDTO[x.fieldName];
        //   }
        // });
        // this.formList1.map(x => {
        //   x.initialValue = recipientDTO[x.fieldName];
        // });
        if (res.errMsg != null && errMsg != undefined) {
          this.$notify({ title: '提示：', message: res.errMsg, type: 'error' });
        }
      }
    },
    formChangeHandle(val) {
      this.saveData = val;
    },
    formChangeHandle1(val) {
      this.saveData1 = val;
    },
    selectChangeHandle(row) {
      this.ids = [];
      if (row.length > 0) {
        this.isCan = true;
        row.map(x => {
          this.ids.push(x.invoiceId);
        });
        return;
      }
      this.isCan = false;
    },
    //取消隐藏
    async cancelHidden() {
      let json = {
        invoiceIds: this.ids
      };
      let res = await cancelHidden(json);

      if (res.resultCode == 200) {
        this.$notify.success({ title: '提示信息', message: '操作成功' });
        this.$emit('close', false, 'refresh');
      }
    },
    closeDrawer() {
      this.$emit('close', false);
    },

    createdSearchFrom() {
      return [
        {
          type: 'INPUT',
          label: '发票号码',
          fieldName: 'goldenInvoiceNo'
        },
        {
          type: 'INPUT',
          label: '发票代码',
          fieldName: 'goldenInvoiceCode'
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 60,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '发票号码',
          dataIndex: 'goldenInvoiceNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '开票日期',
          dataIndex: 'invoiceDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '发票代码',
          dataIndex: 'goldenInvoiceCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '业务类型',
          dataIndex: 'buzinessType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6089'),
          render: props => {
            return <span>{this.createDictText(props.row.buzinessType, '6089')}</span>;
          }
        }
      ];
    }
  }
};
</script>
